package com.xq.sboot.servlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * 功能说明:第一个Servlet类
 * <p>创建时间:2018-12-14 05:54</p>
 *
 * @author <a href="https://gitee.com/gkq/microservice">郭凯强</a>
 * @since 1.0.0
 */
@WebServlet(loadOnStartup = 1, urlPatterns = {"/first/servlet"})
public class FirstServlet extends HttpServlet {
    private final Logger logger = LoggerFactory.getLogger(FirstServlet.class);
    private final Marker marker = MarkerFactory.getMarker("FirstServlet");

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.service(req, resp);
        logger.debug(marker, "获取请求{}", req.getRequestURL());
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        logger.debug(marker, "初始化{}", FirstServlet.class.getName());
    }

    @Override
    public void destroy() {
        super.destroy();
        logger.debug(marker, "退出Servlet容器时销毁{},销毁时刻={}", FirstServlet.class.getName(), new Date());
    }
}
